//
//  UIButton+Extension.swift
//  MicroBlog
//
//  Created by  NorthCity on 15/11/3.
//  Copyright © 2015年  NorthCity. All rights reserved.
//

import UIKit
extension UIButton{
    convenience init(imageName:String,backImageName:String?){
        self.init()
        setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        if let backImageName = backImageName{
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        }
        sizeToFit()
    }
    
//    便利构造函数
    convenience init(title:String,color:UIColor,backImageName:String){
        self.init()
        self.setTitle(title, forState: UIControlState.Normal)
        self.setTitleColor(color, forState: UIControlState.Normal)
        self.setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
    }
    
    convenience init(title:String,fontSize:CGFloat,color:UIColor,imageName:String?,backColor:UIColor? = nil){
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        if let imageName = imageName {
        self.setImage(UIImage(named: imageName), forState:.Normal)
        }
        backgroundColor = backColor
        
        sizeToFit()
    }
    
    
    
}